namespace MobileTrack.Core.Migrations
{
    using System.Data.Entity.Migrations;
    using System.Diagnostics.CodeAnalysis;

    [ExcludeFromCodeCoverage]
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            this.CreateTable(
                "dbo.Celulares",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        Imei = c.Long(),
                        MarcaId = c.Long(nullable: false),
                        FechaIngreso = c.DateTime(nullable: false, storeType: "date"),
                        CodArticulo = c.Long(nullable: false),
                        Descripcion = c.String(nullable: false, maxLength: 75),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Marcas", t => t.MarcaId)
                .Index(t => t.MarcaId);

            this.CreateTable(
                "dbo.Marcas",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        ProveedorId = c.Long(nullable: false),
                        Codigo = c.Long(nullable: false),
                        Nombre = c.String(nullable: false, maxLength: 150),
                        EsOperador = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Proveedores", t => t.ProveedorId, cascadeDelete: true)
                .Index(t => t.ProveedorId);

            this.CreateTable(
                "dbo.Proveedores",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        Nombre = c.String(nullable: false, maxLength: 50),
                        Direccion = c.String(maxLength: 150),
                        Telefono = c.String(maxLength: 25),
                    })
                .PrimaryKey(t => t.Id);

            this.CreateTable(
                "dbo.Abonos",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        MarcaId = c.Long(nullable: false),
                        Descripcion = c.String(nullable: false, maxLength: 85),
                        Precio = c.Decimal(nullable: false, precision: 18, scale: 2),
                        FechaInicio = c.DateTime(nullable: false, storeType: "date"),
                        FechaFin = c.DateTime(nullable: false, storeType: "date"),
                        Proveedor_Id = c.Long(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Marcas", t => t.MarcaId, cascadeDelete: true)
                .ForeignKey("dbo.Proveedores", t => t.Proveedor_Id)
                .Index(t => t.MarcaId)
                .Index(t => t.Proveedor_Id);

            this.CreateTable(
                "dbo.Ventas",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        CelularId = c.Long(nullable: false),
                        SeguimientoId = c.Long(nullable: false),
                        AbonoId = c.Long(nullable: false),
                        Activado = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Celulares", t => t.CelularId)
                .ForeignKey("dbo.Seguimientos", t => t.SeguimientoId, cascadeDelete: true)
                .ForeignKey("dbo.Abonos", t => t.AbonoId, cascadeDelete: true)
                .Index(t => t.CelularId)
                .Index(t => t.SeguimientoId)
                .Index(t => t.AbonoId);

            this.CreateTable(
                "dbo.Seguimientos",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        CelularId = c.Long(nullable: false),
                        SucursalId = c.Long(nullable: false),
                        ResponsableId = c.Guid(nullable: false),
                        Fecha = c.DateTime(nullable: false, storeType: "date"),
                        Comprobante = c.String(nullable: false, maxLength: 55),
                        Estado = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Celulares", t => t.CelularId, cascadeDelete: true)
                .ForeignKey("dbo.Sucursales", t => t.SucursalId, cascadeDelete: true)
                .Index(t => t.CelularId)
                .Index(t => t.SucursalId);

            this.CreateTable(
                "dbo.Sucursales",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        Codigo = c.String(nullable: false, maxLength: 75),
                        Nombre = c.String(nullable: false, maxLength: 150),
                        Direccion = c.String(maxLength: 150),
                        Telefono = c.String(maxLength: 25),
                    })
                .PrimaryKey(t => t.Id);
        }
        
        public override void Down()
        {
            this.DropIndex("dbo.Seguimientos", new[] { "SucursalId" });
            this.DropIndex("dbo.Seguimientos", new[] { "CelularId" });
            this.DropIndex("dbo.Ventas", new[] { "AbonoId" });
            this.DropIndex("dbo.Ventas", new[] { "SeguimientoId" });
            this.DropIndex("dbo.Ventas", new[] { "CelularId" });
            this.DropIndex("dbo.Abonos", new[] { "Proveedor_Id" });
            this.DropIndex("dbo.Abonos", new[] { "MarcaId" });
            this.DropIndex("dbo.Marcas", new[] { "ProveedorId" });
            this.DropIndex("dbo.Celulares", new[] { "MarcaId" });
            this.DropForeignKey("dbo.Seguimientos", "SucursalId", "dbo.Sucursales");
            this.DropForeignKey("dbo.Seguimientos", "CelularId", "dbo.Celulares");
            this.DropForeignKey("dbo.Ventas", "AbonoId", "dbo.Abonos");
            this.DropForeignKey("dbo.Ventas", "SeguimientoId", "dbo.Seguimientos");
            this.DropForeignKey("dbo.Ventas", "CelularId", "dbo.Celulares");
            this.DropForeignKey("dbo.Abonos", "Proveedor_Id", "dbo.Proveedores");
            this.DropForeignKey("dbo.Abonos", "MarcaId", "dbo.Marcas");
            this.DropForeignKey("dbo.Marcas", "ProveedorId", "dbo.Proveedores");
            this.DropForeignKey("dbo.Celulares", "MarcaId", "dbo.Marcas");
            this.DropTable("dbo.Sucursales");
            this.DropTable("dbo.Seguimientos");
            this.DropTable("dbo.Ventas");
            this.DropTable("dbo.Abonos");
            this.DropTable("dbo.Proveedores");
            this.DropTable("dbo.Marcas");
            this.DropTable("dbo.Celulares");
        }
    }
}
